<!--#
layout("/layouts/platform.html"){
#-->
<div id="app" v-cloak>
    <el-row class="header navbar shadow">
        <!--搜索框-->
        <div class="btn-group tool-button mt5">
            <el-input v-model="pageForm.searchKeyword" @keyup.enter.native="doSearch" placeholder="昵称或者手机号码或真实姓名"
                      size="medium"></el-input>
        </div>
        <div class="btn-group tool-button mt5">
            <el-date-picker
                    v-model="searchDate"
                    type="datetimerange"
                    :picker-options="pickerOptions"
                    range-separator="至"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                    align="right"
                    size="medium"
                    :default-time="['00:00:00', '23:59:59']"
                    value-format="yyyy-MM-dd HH:mm:ss">
            </el-date-picker>
        </div>
        <!--搜索条件-->
        <div class="btn-group tool-button mt5">
            <el-select v-model="pageForm.status" placeholder="请选择状态"
                       size="medium">
                <el-option
                        v-for="item in statusOptions"
                        :key="item.val"
                        :label="item.name"
                        :value="item.val">
                </el-option>
            </el-select>
        </div>
        <!--搜索按钮-->
        <div class="btn-group tool-button mt5">
            <el-button slot="append" icon="el-icon-search" @click="doSearch" size="medium"></el-button>
        </div>
    </el-row>
    <el-row class="el-table-container">
        <el-table
                :data="tableData"
                @sort-change='pageOrder'
                size="small"
                header-align="center"
                style="width: 100%"
                @selection-change="handleSelectionChange"
                :default-sort="{prop: 'opAt', order: 'descending'}">
            <el-table-column
                    type="selection"
                    width="35">
            </el-table-column>

            <el-table-column label="用户名称" header-align="left" prop="username"
                             :show-overflow-tooltip="true">
            </el-table-column>

            <el-table-column label="用户昵称" header-align="left" prop="nickname"
                             :show-overflow-tooltip="true">
            </el-table-column>

            <el-table-column label="手机号码" header-align="left" prop="phone"
                             :show-overflow-tooltip="true">
            </el-table-column>

            <el-table-column sortable label="姓名" header-align="center" align="center" prop="realname">
            </el-table-column>
            <el-table-column sortable label="身份证" header-align="center" align="center" prop="idcard">
            </el-table-column>
            <el-table-column sortable label="微信" header-align="center" align="center" prop="wechatid">
            </el-table-column>
            <el-table-column sortable label="内容" header-align="center" align="center" prop="content">
            </el-table-column>
            <!--User启用状态-->
            <el-table-column sortable label="申请时间" header-align="center" align="center" prop="">
                <template slot-scope="scope">
                    <span > {{formatAt(scope.row.ctat)}}</span>
                </template>
            </el-table-column>  <!--User启用状态-->

            <el-table-column label="操作" header-align="center" prop="id"
                             :show-overflow-tooltip="true" align="center" width="120">
                <template slot-scope="scope">
                    <el-dropdown v-if="scope.row.status==0" @command="dropdownCommand">
                        <el-button size="mini">
                            <i class="ti-settings"></i>
                            <span class="ti-angle-down"></span>
                        </el-button>
                        <el-dropdown-menu slot="dropdown">

                            <el-dropdown-item :command="{row:scope.row,type:'enable'}" v-if="scope.row.status==0"
                            >
                                通过
                            </el-dropdown-item>
                            <el-dropdown-item :command="{row:scope.row,type:'disable'}" v-if="scope.row.status==0"
                            >
                                驳回
                            </el-dropdown-item>
                        </el-dropdown-menu>
                    </el-dropdown>
                    <span v-else>
                        <span v-if="scope.row.status==1">已通过</span>
                        <span v-else>已驳回</span>
                    </span>
                </template>
            </el-table-column>

        </el-table>
    </el-row>
    <el-row class="el-pagination-container">
        <el-pagination
                @size-change="pageSizeChange"
                @current-change="pageNumberChange"
                :current-page="pageForm.pageNumber"
                :page-sizes="[10, 20, 30, 50]"
                :page-size="pageForm.pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="pageForm.totalCount">
        </el-pagination>
    </el-row>



</div>
<script>
    function getParams(key) {
        var result = {};
        var paramStr = encodeURI(window.document.location.search);
        if (paramStr) {
            paramStr = paramStr.substring(1);
            var param4Map = paramStr.split('&');
            for (var p = 0; p < param4Map.length; p++) {
                result[param4Map[p].split('=')[0]] = unescape(param4Map[p].split('=')[1]);
            }
        }
        let resultElement = result[key];
        return resultElement===undefined?"":resultElement;
    }
    new Vue({
        el: "#app",
        data: function () {
            return {
                statusOptions: [{
                    val: '',
                    name: '全部类型'
                }, {
                    val: 0,
                    name: '待审核'
                }, {
                    val: 1,
                    name: '通过'
                }, {
                    val: -1,
                    name: '失败'
                }],
                pickerOptions: {
                    disabledDate: function (time) {
                        var threeMonths = moment().add(-3, 'months').valueOf();
                        return time.getTime() > new Date(new Date(new Date().toLocaleDateString()).getTime() + 24 * 60 * 60 * 1000 - 1)
                            || time.getTime() < threeMonths;
                    },
                    shortcuts: [{
                        text: '最近一周',
                        onClick: function (picker) {
                            var end = new Date();
                            var start = new Date();
                            var temp = moment().add(-1, 'weeks').valueOf();
                            start.setTime(temp);
                            picker.$emit('pick', [start, end]);
                        }
                    }, {
                        text: '最近一个月',
                        onClick: function (picker) {
                            var end = new Date();
                            var start = new Date();
                            var temp = moment().add(-1, 'months').valueOf();
                            start.setTime(temp);
                            picker.$emit('pick', [start, end]);
                        }
                    }, {
                        text: '最近三个月',
                        onClick: function (picker) {
                            var end = new Date();
                            var start = new Date();
                            var temp = moment().add(-3, 'months').valueOf();
                            start.setTime(temp);
                            picker.$emit('pick', [start, end]);
                        }
                    }]
                },
                searchDate: [],
                selectData: [],
                pageForm: {
                    searchName: "",
                    searchKeyword: getParams("userName"),
                    pageNumber: 1,
                    pageSize: 10,
                    totalCount: 0,
                    pageOrderName: "opAt",
                    pageOrderBy: "descending",
                },
                tableData: [],
                formData: {
                    id: "",
                },
                formData1: {
                    id: "",
                },
                formRules: {
                    toUser: [
                        {required: true, message: '充值对象', trigger: 'blur'}
                    ],
                    amount: [
                        {required: true, message: '金额', trigger: 'blur'}
                    ]
                },
                options:[],
                loading:false,
                showRestriction:false
            }
        },
        methods: {
            pageOrder: function (column) {//按字段排序
                this.pageForm.pageOrderName = column.prop;
                this.pageForm.pageOrderBy = column.order;
                this.pageData();
            },
            pageNumberChange: function (val) {//页码更新操作
                this.pageForm.pageNumber = val;
                this.pageData();
            },
            pageSizeChange: function (val) {//分页大小更新操作
                this.pageForm.pageSize = val;
                this.pageData();
            },
            doSearch: function () {
                this.pageForm.pageNumber = 1;
                this.pageData();
            },
            pageData: function () {//加载分页数据
                var self = this;
                sublime.showLoadingbar();//显示loading
                if (self.searchDate) {
                    self.pageForm.searchDate = self.searchDate.toString();
                } else {
                    self.pageForm.searchDate = "";
                }
                $.post(base + "/platform/user/certify/data", self.pageForm, function (data) {
                    sublime.closeLoadingbar();//关闭loading
                    if (data.code == 0) {
                        self.tableData = data.data.list;
                        self.pageForm.totalCount = data.data.totalCount;
                    } else {
                        self.$message({
                            message: data.msg,
                            type: 'error'
                        });
                    }
                }, "json");
            },
            formatAt: function (val) {
                if (val > 0)
                    return moment(val * 1000).format("YYYY-MM-DD HH:mm");
                return "";
            },
            handleSelectionChange: function (val) {
                this.selectData = val;
            },
            dropdownCommand: function (command) {//监听下拉框事件
                var self = this;
                // 启用，禁用按钮
                if ("enable" == command.type || "disable" == command.type) {
                    $.post(base + "/platform/user/certify/edit",{id:command.row.id,result:"enable" == command.type}, function (data) {
                        if (data.code == 0) {
                            self.$message({
                                message: data.msg,
                                type: 'success'
                            });
                            self.pageData();
                        } else {
                            self.$message({
                                message: data.msg,
                                type: 'error'
                            });
                        }
                    }, "json");
                }


            },
            getAccounts:function (str) {
                var _this = this;
                $.post(base + "/platform/user/manager/searchAccount" , {key:str}, function (data) {
                    _this.options = data.code == 0 ? data.data.list.map(ite => {
                            // ite.label =ite.nickName+'#<span style="color: darkblue">'+ite.phone+'</span>$<span style="color: darkred">'+ite.balance+'</span>'
                            ite.label =ite.nickName+'#'+ite.phone+'$'+ite.balance
                            return ite
                        }
                    ) : [];
                }, "json");
            },
            restrictionEdit:function (userId) {
                let param = {};
                if(typeof userId == "string"){
                    param = {userId}
                }
                var _this = this;
                this.formData1 = {};
                this.showRestriction = true;
                $.post(base + "/platform/user/restriction/showRestriction" , param, function (data) {
                    _this.formData1 = data.data;
                }, "json");
            },
            editRestrictionDo: function () {
                var self = this;
                this.showRestriction = false;
                $.post(base + "/platform/user/restriction/editDo" , this.formData1, function (data) {
                    if (data.code == 0) {
                        self.$message({
                            message: data.msg,
                            type: 'success'
                        });
                        self.addDialogVisible = false;
                        self.pageData();
                    } else {
                        self.$message({
                            message: data.msg,
                            type: 'error'
                        });
                    }
                }, "json");
            }
        },
        created: function () {
            this.pageData();
        }
    });
</script>
<!--#
}
#-->